<template>
	<el-container>
		<el-header style="height: auto;">
			<sc-select-filter :data="filterData" :label-width="80" @on-change="filterChange"></sc-select-filter>
		</el-header>
		<el-header>
			<div class="left-panel">
			</div>
			<div class="left-panel"> </div>
			<div class="right-panel">
				<div class="right-panel-search">
					<el-input v-model="search.keyword" placeholder="任务名称 / 项目名称" clearable></el-input>
					<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
				</div>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable ref="table" :apiObj="apiObj" row-key="taskId" stripe remoteSort remoteFilter>
				<el-table-column label="#" type="index" width="50"></el-table-column>
				<el-table-column label="任务名称" prop="text" width="300" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="项目名称" prop="title" width="400" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="项目分类" prop="sortName" width="100"></el-table-column>
				<el-table-column label="开始日期" prop="startDate" width="100"></el-table-column>
				<el-table-column label="工期" prop="duration" width="100">
					<template #default="scope">
						{{scope.row.duration}}/人
					</template>
				</el-table-column>
				<el-table-column label="进度" prop="progress" width="100">
					<template #default="scope">
						{{Number(scope.row.progress)*100}}%
					</template>
				</el-table-column>
				<el-table-column label="操作" fixed="right" align="right" width="250">
					<template #default="scope">
						<el-button-group>
							<el-button text type="primary" size="small" @click="table_show(scope.row, scope.$index)">查看</el-button>
							<el-button text type="primary" size="small" @click="setProcess(scope.row, scope.$index)">汇报</el-button>
							<el-button text type="primary" size="small" @click="setBpmFlow(scope.row, scope.$index)">流程</el-button>
							<el-button text type="primary" size="small" @click="setProblem(scope.row, scope.$index)">反馈</el-button>
							<el-popconfirm title="确定挂起吗？" @confirm="stopTask(scope.row, scope.$index)" v-if="scope.row.status=='0'">
								<template #reference>
									<el-button text type="primary" size="small">挂起</el-button>
								</template>
							</el-popconfirm>
							<el-popconfirm title="确定恢复吗？" @confirm="revBack(scope.row, scope.$index)" v-if="scope.row.status=='1'">
								<template #reference>
									<el-button text type="primary" size="small">恢复</el-button>
								</template>
							</el-popconfirm>
						</el-button-group>
					</template>
				</el-table-column>
			</scTable>
		</el-main>
	</el-container>
	<problem-dialog v-if="dialog.problemSave" ref="problemDialog" @success="handleSaveSuccess" @closed="dialog.problemSave=false"></problem-dialog>
	<process-dialog v-if="dialog.processSave" ref="processDialog" @success="handleSaveSuccess" @closed="dialog.processSave=false"></process-dialog>
	<sendBpmDialog v-if="dialog.sendBpmSave" ref="sendBpmDialog" @closed="dialog.sendBpmSave=false"></sendBpmDialog>
	<recordDetails v-if="dialog.detailsSave" ref="detailsDialog" @closed="dialog.detailsSave=false"></recordDetails>

</template>

<script>
import scSelectFilter from '@/components/scSelectFilter'
import recordDetails from './details'
import problemDialog from './problem'
import processDialog from './process'
import sendBpmDialog from './sendBpmDialog'
export default {
	name: 'Project Task Manage',
	components: {
		scSelectFilter,
		recordDetails,
		problemDialog,
		processDialog,
		sendBpmDialog
	},
	data() {
		return {
			dialog: {
				save: false,
				detailsSave:false,
				problemSave:false,
				sendBpmSave:false
			},
			filterData: [
				{
					title: "日期范围",
					key: "date",
					multiple: false,
					options: [
						{
							label: "全部",
							value: ""
						},
						{
							label: "今日",
							value: "1"
						},
						{
							label: "昨日",
							value: "2"
						},
						{
							label: "一周内",
							value: "3"
						},
						{
							label: "一月内",
							value: "4"
						},
						{
							label: "一月前",
							value: "5"
						}
					]
				},
				{
					title: "项目类型",
					key: "proSort",
					multiple: false,
					options:[{
						label: "全部",
						value: ""
					}]
				}],
			apiObj: this.$API.project.proTask.getMyTaskWorkList,
			search: {
				date:'',
				proSort:'',
				status:'',
				keyword: null
			}
		}
	},
	mounted() {
		this.getProSort();
	},
	methods: {
		async getProSort()
		{
			var res = await this.$API.project.proSort.getProSort.get();
			if (res.code == 200) {
				this.filterData[1].options=this.filterData[1].options.concat(res.data);
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		filterChange(data){
			this.search.date = data.date;
			this.search.proSort = data.proSort;
			this.search.status = data.status;
			this.$refs.table.upData(this.search)
		},
		setProblem(row){
			this.dialog.problemSave = true
			this.$nextTick(() => {
				this.$refs.problemDialog.open().setData({proId:row.proId,taskId:row.taskId})
			})
		},
		setBpmFlow(row)
		{
			this.dialog.sendBpmSave = true
			this.$nextTick(() => {
				this.$refs.sendBpmDialog.open().setData({flowId:row.flowId})
			})
		},
		setProcess(row)
		{
			this.dialog.processSave = true
			this.$nextTick(() => {
				this.$refs.processDialog.open().setData({taskId:row.taskId,progress:row.progress})
			})
		},
		//查看
		table_show(row) {
			this.dialog.detailsSave = true
			this.$nextTick(() => {
				this.$refs.detailsDialog.open().setData(row)
			})
		},
		//删除
		async table_del(row) {
			var reqData = {taskId: row.taskId}
			var res = await this.$API.project.proTask.deleteProTask.post(reqData);
			if (res.code == 200) {
				this.$refs.table.refresh()
				this.$message.success("删除成功")
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		async stopTask(row)
		{
			var reqData = {taskId: row.taskId,status:'1'}
			var res = await this.$API.project.proTask.updateProTask.post(reqData);
			if (res.code == 200) {
				this.$refs.table.refresh()
				this.$message.success("任务已挂起")
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		async revBack(row){
			var reqData = {taskId: row.taskId,status:'0'}
			var res = await this.$API.project.proTask.updateProTask.post(reqData);
			if (res.code == 200) {
				this.$refs.table.refresh()
				this.$message.success("任务已恢复")
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//搜索
		async upsearch() {
			this.$refs.table.upData(this.search)
		},
		//本地更新数据
		handleSaveSuccess() {
			this.$refs.table.refresh()
		}
	}
}
</script>

<style>
</style>
